home *** CD-ROM | disk | FTP | other *** search
/ Aminet 4 / Aminet 4 - November 1994.iso / aminet / dev / c / cweb31p9d.lha / CWeb / arexx / start_web.ced < prev   
Text File  |  1994-06-24  |  13KB  |  362 lines

  1. /*
  2.  * AREXX $VER: Start_Web.ced 3.8 (24.6.1994)
  3.  *
  4.  * DESCRIPTION: This AREXX script saves and weaves or tangles the current
  5.  *              CED Pro 3 view (it is very easy to use this script with
  6.  *              version 2 of CED, just look for the keyword `CED2' and
  7.  *              change by hand).  Then it loads the resulting `.tex' or
  8.  *              `.c' or `.cpp' file into a new view.  If a changefile is
  9.  *              present to the webfile in the current view, i.e., a file
  10.  *              with extension `.ch' instead of `.w' (or `.web' or `.wpp'),
  11.  *              it will be taken into account.  To use this script, install
  12.  *              two calls in the DOS/ARexx interface of CED of the form
  13.  *
  14.  *                 CWeb:ARexx/Start_Web CTangle
  15.  *                 CWeb:ARexx/Start_Web CWeave
  16.  *
  17.  *              If you are a COOL programmer and want to receive C++ source
  18.  *              files with an appropriate extension, you should add a third
  19.  *              call of the form
  20.  *
  21.  *                 CWeb:ARexx/Start_Web CTangle ++
  22.  *
  23.  *              with two arguments, so that CTANGLE will produce `.cpp'
  24.  *              file extensions.  You don't need a second entry for CWEAVE
  25.  *              when using C++, since CWEAVE always produces `.tex' files.
  26.  *
  27.  * CREATION DATE: 11.09.1992 (V0.1 and V0.2)
  28.  *
  29.  * AUTHOR: Andreas Scherer
  30.  *         Abt-Wolf-Straße 17
  31.  *         96215 Lichtenfels
  32.  *         Germany
  33.  *
  34.  * CHANGES: 25.10.1992: `change file' included (V0.3)
  35.  *          28.02.1993: `.web' extension is now permissible (V0.4)
  36.  *                      Options `+a +g' are default in my CWEAVE version.
  37.  *          19.03.1993: Absolute path name of the WEB file is taken into
  38.  *                      account due to CWEB 2.7 (V0.5)
  39.  *          31.08.1993: CWEB 2.7 [p6b] now returns RC=[0,5,10,20];
  40.  *                      give appropriate messages in CED (V0.6)
  41.  *          07.09.1993: Rely on system path to find CTANGLE/CWEAVE (V0.7)
  42.  *          03.10.1993: Refinement of program call for Cygnus Ed 3.5:
  43.  *                      ARexx<-->CED window isn't temporary anymore;
  44.  *                      output of CTANGLE/CWEAVE will be redirected
  45.  *                      to the log file `T:web.log'.  This file is loaded
  46.  *                      in case of an error (V0.8)
  47.  *          06.10.1993: Single script for both CTANGLE and CWEAVE (V1.0)
  48.  *          07.10.1993: Localization of all requester texts for German
  49.  *                      and English users.  Catalog with the English
  50.  *                      translation provided.  These features work for
  51.  *                      WorkBench 2.1 and higher; the script works with
  52.  *                      lower versions too (V1.1)
  53.  *          09.10.1993: Updated for CWEB 2.8 (V1.2)
  54.  *          20.10.1993: Allow special device name "RAM DISK:" (V1.3)
  55.  *          25.10.1993: Updated for CWEB 3.0 (V2.0)
  56.  *          04.11.1993: New patch level CWEB 3.0 [p8e] (V2.1)
  57.  *          10.11.1993: Saving bug fixed, a negative number of changes
  58.  *                      is possible for the current view (V2.2)
  59.  *          18.11.1993: Updated for CWEB 3.1 (V2.3)
  60.  *          19.11.1993: Naming simplification (V2.4)
  61.  *          21.11.1993: When called `CTangle ++', this script produces
  62.  *                      C++ output files with `.cpp' extensions.  Also
  63.  *                      the new extension `.wpp' is permissible (V3.0)
  64.  *          30.11.1993: New patch level CWEB 3.1 [p9a] (V3.1)
  65.  *          06.12.1993: Localization improved and new catalog name to
  66.  *                      avoid collisions with the localization of
  67.  *                      CWEB 3.1 [p9b] (V3.2)
  68.  *          01.01.1994: Pre-V38 users want to see the warning and
  69.  *                      error messages as well (V3.3)
  70.  *          31.01.1994: We are at patch level [p9c].
  71.  *                      RESULTFILE is not editable. (V3.4)
  72.  *          02.04.1994: Localization improved; only one set of
  73.  *                      default strings needed (V3.5)
  74.  *          13.04.1994: PROG_NAME tested in uppercase mode (V3.6)
  75.  *          13.05.1994: New patch level [p9d]. (V3.7)
  76.  *          24.06.1994: New option `m'.  (V3.8)
  77.  *
  78.  * COPYRIGHT: (c) 1992-1994 Andreas Scherer
  79.  *
  80.  * Permission is granted to make and distribute verbatim copies of this
  81.  * document provided that the copyright notice and this permission notice
  82.  * are preserved on all copies.
  83.  *
  84.  * Permission is granted to copy and distribute modified versions of this
  85.  * document under the conditions for verbatim copying, provided that the
  86.  * entire resulting derived work is distributed under the terms of a
  87.  * permission notice identical to this one.
  88.  */
  89.  
  90. Options FailAt 21
  91. Options Results
  92.  
  93. /*
  94.  * The pre-1.0 version of this script actually consisted of two
  95.  * separate scripts for CTANGLE and CWEAVE.  To facilitate further
  96.  * improvements, the name of the program we want to call is passed
  97.  * as a single argument on startup, possibly with a second `++' for
  98.  * C++ programmers.  It should be one of the strings `CTangle',
  99.  * `CTangle ++' (watch your space!) or `CWeave'.  (You don't need an
  100.  * extra `CWeave ++' command.)
  101.  */
  102. Parse Arg PROG_NAME CPP .
  103.  
  104. /*
  105.  * Since CTANGLE either has the same command line options as CWEAVE
  106.  * or ignores the others it is save to have a common specification
  107.  * of activated or deactivated switches.  According to the CWEB user
  108.  * manual options are activated by `+' and deactivated by `-'.
  109.  * The current implementation of the programs understand the following
  110.  * list of command line options:
  111.  *
  112.  *     a - Amiga-defined identifiers are keywords [+] (W)
  113.  *     b - Print a banner line                    [+] (TW)
  114.  *     f - Force line breaks                      [+] (W)
  115.  *     g - Use German macros `gcwebmac.tex'       [+] (W)
  116.  *     h - Print a happy message                  [+] (TW)
  117.  *     i - Indent parameter declarations          [+] (W)
  118.  *     m - ARexx communication to SAS/C's browser [-] (TW)
  119.  *     o - Separate declarations and statements   [+] (W)
  120.  *     p - Give progress report                   [+] (TW)
  121.  *     s - Show statistics                        [-] (TW)
  122.  *     x - Include indexes and table of contents  [+] (W)
  123.  *
  124.  * The hard-wired defaults are in brackets.  A `T' or `W' in
  125.  * braces indicates that CTANGLE or CWEAVE acknowledges the option.
  126.  *
  127.  * For the purposes of this script I set the default language
  128.  * to German and request that the statistics are written to the
  129.  * log file as explained below.  Also I prefer that parameter
  130.  * declarations do not get indented in old-style function headers.
  131.  */
  132. WEB_OPTS = "-i +s"
  133.  
  134. /*
  135.  * WorkBench 2.1/3.0 users are provided with localized messages in
  136.  * their system default language.  This may be either German or English.
  137.  * (Other languages are welcome!)  Default in this script, in case the
  138.  * catalogs can not be used, is the German version for all arguments
  139.  * to the `GetCatalogStr' function.  (You will have to edit these strings
  140.  * by hand if you don't have WorkBench 2.1/3.0, so go get the latest
  141.  * version of the best!)
  142.  */
  143. MSG_ERROR_EXTENSION = "Fehler, die Datei muß eine Endung `.w', `.web' oder `.wpp' haben."
  144. MSG_ERROR_FATAL     = "mit fatalem Fehler abgebrochen! Keine Ausgabe!"
  145. MSG_ERROR_ERROR     = "beendet mit Fehler! Ausgabe fehlerhaft!"
  146. MSG_ERROR_WARNING   = "beendet mit Warnung!" || '0A'X || "Ausgabe wahrscheinlich korrekt."
  147. MSG_ERROR_END       = "Fehler bei"
  148.  
  149. If 38 <= MyGetEnv("WORKBENCH") Then
  150.   If ~Show('Libraries','locale.library') Then
  151.     Call AddLib('locale.library',0,-30)
  152.  
  153. LOCALE_FOUND = Show('Libraries','locale.library')
  154.  
  155. If 1 = LOCALE_FOUND Then Do
  156.   catalog = OpenCatalog("cweb_arexx.catalog","deutsch",0);
  157.   MSG_ERROR_EXTENSION = GetCatalogStr(catalog,0,MSG_ERROR_EXTENSION)
  158.   MSG_ERROR_FATAL     = GetCatalogStr(catalog,1,MSG_ERROR_FATAL)
  159.   MSG_ERROR_ERROR     = GetCatalogStr(catalog,2,MSG_ERROR_ERROR)
  160.   MSG_ERROR_WARNING   = GetCatalogStr(catalog,3,MSG_ERROR_WARNING)
  161.   MSG_ERROR_END       = GetCatalogStr(catalog,4,MSG_ERROR_END)
  162. End
  163.  
  164. /*
  165.  * Give a little progress message to the Cygnus Ed 3.5 user.
  166.  * Comment this out if you use Cygnus Ed 2.12 (CED2).
  167.  */
  168. DM PROG_NAME "V3.1 [p9d] Copyright © 1993-1994 Andreas Scherer"
  169.  
  170. /*
  171.  * Get the full filename from CED.
  172.  * CED2 uses numbers instead of strings.
  173.  */
  174. Status FileName /* 19  */
  175. FULLNAME = RESULT
  176.  
  177. /*
  178.  * Make "RAM DISK:" a special case.
  179.  */
  180. If "RAM DISK:" = Upper(Left(FULLNAME,9)) Then
  181.   FULLNAME = "RAM:" ||  SubStr(FULLNAME,10)
  182.  
  183. /*
  184.  * Error messages and warnings of CTANGLE and CWEAVE will be written
  185.  * to a temporary log file, which can be loaded for debugging.  It will
  186.  * contain the complete screen output of CTANGLE/CWEAVE.
  187.  */
  188. LOGFILE = "T:cweb.log"
  189.  
  190. /*
  191.  * We need an absolute file name.
  192.  */
  193. IVOL     = Index(FULLNAME,":")
  194. IDIRS    = LastPos("/",SubStr(FULLNAME,1+IVOL))
  195. FILEONLY = SubStr(FULLNAME,IVOL+1+IDIRS)
  196. IBASE    = LastPos(".",FILEONLY)
  197.  
  198. If 0 = IBASE Then
  199.   IBASE = Length(FILEONLY)
  200. Else
  201.   IBASE = IBASE - 1
  202.  
  203. /*
  204.  * CWEB files normally have a `.w' extension.
  205.  */
  206. If "" = SubStr(FULLNAME,1+IVOL+IDIRS+IBASE) | "W" ~= Upper(Right(FULLNAME,1)) Then Do
  207.  
  208. /*
  209.  * But you may also use the `.web' form.
  210.  */
  211.   If "" = SubStr(FULLNAME,1+IVOL+IDIRS+IBASE) | "WEB" ~= Upper(Right(FULLNAME,3)) Then Do
  212.  
  213. /*
  214.  * And for C++ programmers there is even the `.wpp' form, so they can mix
  215.  * ANSI-C and COOL programs in the same directory.
  216.  */
  217.     If "" = SubStr(FULLNAME,1+IVOL+IDIRS+IBASE) | "WPP" ~= Upper(Right(FULLNAME,3)) Then Do
  218.  
  219. /*
  220.  * No other file extensions will be accepted.
  221.  */
  222.       Okay1 MSG_ERROR_EXTENSION
  223.       Call EndGame
  224.     End
  225.   End
  226. End
  227.  
  228. /*
  229.  * Fix the full name of the file including device or directory name.
  230.  */
  231. If 0 = IVOL Then Do
  232.   DIREC = Pragma('d')
  233.   If '/' ~= Right(DIREC,1) & ':' ~= Right(DIREC,1) Then
  234.     DIREC = DIREC||'/'
  235.   FULLNAME = DIREC||FULLNAME
  236.   Drop DIREC
  237. End
  238.  
  239. /*
  240.  * In case there is a `change file', it has a `.ch' extension.  If there
  241.  * is no change file in the current directory a dummy value is inserted.
  242.  */
  243. CHANGEFILE = Left(FULLNAME,IVOL+IDIRS+IBASE)||'.ch'
  244.  
  245. If ~Exists(CHANGEFILE) Then
  246.   CHANGEFILE = "-"
  247.  
  248. /*
  249.  * This file will hopefully be created by CTANGLE/CWEAVE.
  250.  */
  251. RESULTFILE = Left(FULLNAME,IVOL+IDIRS+IBASE)
  252.  
  253. If 'CTANGLE' = Upper(PROG_NAME) Then Do
  254.   If '++' = CPP Then
  255.     RESULTFILE = RESULTFILE||'.cpp'
  256.   Else
  257.     RESULTFILE = RESULTFILE||'.c'
  258. End
  259. If 'CWEAVE' = Upper(PROG_NAME) Then
  260.   RESULTFILE = RESULTFILE||'.tex'
  261.  
  262. /*
  263.  * Remember the path name of the WEB file.
  264.  */
  265. PATHNAME = Left(FULLNAME,IVOL+IDIRS)
  266.  
  267. Drop IVOL IDIRS IBASE
  268.  
  269. /*
  270.  * Save only if the file has been modified.  So get the number of changes
  271.  * to the file in the current view.  This number can be negative! so test
  272.  * for unequal to zero instead of greater than zero.  CED2 uses numbers
  273.  * instead of strings.
  274.  */
  275. Status NumChanges /* 18  */
  276. If 0 ~= RESULT Then
  277.   Save
  278.  
  279. /*
  280.  * Change the current directory first.
  281.  */
  282. Pragma('Directory',PATHNAME)
  283.  
  284. /*
  285.  * Now call the CTANGLE or the CWEAVE program.  We don't change the
  286.  * host address, because there may be more than one Cygnus Ed running,
  287.  * each having its own ARexx port name and we want to see the results
  288.  * in the right one.
  289.  */
  290. Address COMMAND PROG_NAME WEB_OPTS FULLNAME CHANGEFILE RESULTFILE ">" LOGFILE
  291.  
  292. /*
  293.  * Patch level [p6b] of `common.w' now returns error and warning codes
  294.  * as defined for the AMIGA system.  Take appropriate actions.
  295.  */
  296. If 20 = RC Then Do
  297.   Okay1 PROG_NAME MSG_ERROR_FATAL
  298.   OW LOGFILE /* Use 'jump to file' with CED2.  */
  299.   Call EndGame
  300. End; Else If 10 = RC Then Do
  301.   Okay1 PROG_NAME MSG_ERROR_ERROR
  302.   OW LOGFILE /* Use 'jump to file' with CED2.  */
  303.   Call EndGame
  304. End; Else If 5 = RC Then Do
  305.   Okay2 PROG_NAME MSG_ERROR_WARNING
  306.  
  307.   If 0 = RESULT Then Do
  308.     OW LOGFILE /* Use 'jump to file' with CED2.  */
  309.     Call EndGame
  310.   End
  311. End
  312.  
  313. /*
  314.  * Make sure the WEB-file is loaded.  This works with CED 3.5+ only.
  315.  */
  316. OW FULLNAME
  317.  
  318. /*
  319.  * Now load the resulting `.tex' or `.c' file into a new CED view.
  320.  */
  321. If Exists(RESULTFILE) Then Do
  322.   'jump to file "'RESULTFILE'"'
  323.  
  324. /*
  325.  * The `.tex'- or `.c'-file is already in a CED view.  Leave it, then
  326.  * load it again.  Is there a better way to do this?
  327.  */
  328.   If 0 ~= RESULT Then
  329.     Quit
  330.  
  331.   Open new
  332.   Open RESULTFILE
  333.  
  334. /*
  335.  * Make sure the resultfile can't be edited.
  336.  */
  337.   Status Editable
  338.   If 1 = RESULT Then
  339.     Editable File
  340. End; Else
  341.   Okay1 MSG_ERROR_END PROG_NAME
  342.  
  343. EndGame:
  344.   If 1 = LOCALE_FOUND Then
  345.     CloseCatalog(catalog);
  346.   DM /* Comment this out when using CED2.  */
  347.   Exit
  348. Return
  349.  
  350. /*
  351.  * When will ARexx supply GetEnv/SetEnv?
  352.  */
  353. MyGetEnv: Procedure
  354. Parse Arg NAME
  355.  
  356. If Open(TEMPFILE,"ENV:"||NAME,'r') Then Do
  357.   GIVES = Readln(TEMPFILE)
  358.   Call Close TEMPFILE
  359. End; Else GIVES = 37
  360.  
  361. Return GIVES
  362.